@extends('common.admin_template')

@section('content')
    <div class="boxWidth">
        <h3>添加用户</h3>
        @include('common.notice_msg')
        <form method="post" action="{{url('admin/user/save')}}">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        @if($User)<input type="hidden" name="User[id]" value="{{ $User->id}}">@endif
        <div class="row editFormItem"><div class="col-xs-12">用户等级列表：游客 - 0， 注册用户 - 2， 待审企业 - 3， 企业用户 - 4， 商户 - 5， 编辑 - 8， 管理员 - 10</div></div>
        <div class="row editFormItem">
            <div class="col-xs-2"><span>用户名</span></div>
            <div class="col-xs-5{{ $errors->has('name') ? ' has-error' : '' }}" id="nameBox"><input type="text" class="form-control" id="name" name="User[name]" value="{{ old('User')?old('User')['name']:$User?$User->name:"" }}" required></div>
            @if ($errors->has('name'))<div class="col-xs-5" ><span class="help-block"><strong>{{ $errors->first('name') }}</strong></span></div>@endif
        </div>
        <div class="row editFormItem">
            <div class="col-xs-2"><span>邮箱</span></div>
            <div class="col-xs-5{{ $errors->has('email') ? ' has-error' : '' }}" id="mailBox"><input type="email" class="form-control" id="mail" name="User[email]" value="{{ old('User')?old('User')['email']:$User?$User->email:""  }}" required></div>
            @if ($errors->has('email'))<div class="col-xs-5" ><span class="help-block"><strong>{{ $errors->first('email') }}</strong></span></div>@endif
        </div>
        <div class="row editFormItem">
            <div class="col-xs-2"><span>手机 (选填)</span></div>
            <div class="col-xs-5" id="phoneBox"><input type="text" class="form-control" id="phone" name="User[phone]" value="{{ old('User')?old('User')['phone']:$User?$User->phone:""  }}"></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-2"><span>真名 (选填)</span></div>
            <div class="col-xs-5"><input type="text" class="form-control" name="User[real_name]" value="{{ old('User')?old('User')['real_name']:$User?$User->real_name:""  }}"></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-2"><span>公司 (选填)</span></div>
            <div class="col-xs-5"><input type="text" class="form-control" name="User[company]" value="{{ old('User')?old('User')['company']:$User?$User->company:""  }}"></div>
        </div>
        <div class="row editFormItem">
            <div class="col-xs-2"><span>介绍 (选填)</span></div>
            <div class="col-xs-5"><textarea type="text" class="form-control"  name="User[content]">{{ old('User')?old('User')['content']:$User?$User->content:""  }}</textarea></div>
        </div>
        @if($User)
            <div class="row editFormItem">
                <div class="col-xs-2"><span>新密码 (选填)</span></div>
                <div class="col-xs-5{{ $errors->has('password') ? ' has-error' : '' }}" id="passwordBox"><input type="text" class="form-control" id="password" name="User[password]" value="{{ old('User')['password']}}"></div>
                @if ($errors->has('password'))<div class="col-xs-5" ><span class="help-block"><strong>{{ $errors->first('password') }}</strong></span></div>@endif
            </div>
        @else
            <div class="row editFormItem">
                <div class="col-xs-2"><span>密码</span></div>
                <div class="col-xs-5{{ $errors->has('password') ? ' has-error' : '' }}" id="passwordBox"><input type="text" class="form-control" id="password" name="User[password]" value="{{ old('User')['password']}}" required></div>
                @if ($errors->has('password'))<div class="col-xs-5" ><span class="help-block"><strong>{{ $errors->first('password') }}</strong></span></div>@endif
            </div>
        @endif


            <div class="row editFormItem" @if(($User&&$User->id==$CurrentUser->id))style="display: none" @endif>
                <div class="col-xs-2"><span>角色</span></div>
                <div class="col-xs-5" id="tagNameBox">
                    <select name="User[level]" id="level">
                        <option value="0">游客</option>
                        <option value="2">注册用户</option>
                        <option value="3">待审企业</option>
                        <option value="4">企业用户</option>
                        <option value="5">商户</option>
                        <option value="8">编辑</option>
                        <option value="10">管理员</option>
                    </select>
                </div>
            </div>

        <div class="row editFormItem">
            <div class="col-xs-3"><button class="btn btn-primary addInputBtn" type="submit" id="formSubmit">添加用户</button></div>
            <div class="col-xs-8"></div>
        </div>
        </form>
    </div>
@stop
@section('js')
    <script>
        (function () {
            @if($User)
                $('#level').val({{$User->level}});
                $('#formSubmit').on('click',function (e) {
                    var length = $('#password').val().length;
                    if(length < 5&&length!==0){
                        $('#passwordBox').addClass('has-error');
                        e.preventDefault();
                    }
                });
            @else
                $('#formSubmit').on('click',function (e) {
                    if($('#password').val().length < 5){
                        $('#passwordBox').addClass('has-error');
                        e.preventDefault();
                    }
                });
            @endif
        })();
    </script>
@stop